package com.system.business.service.impl;

import com.system.business.been.IntervalPlan;
import com.system.business.been.IntervalPlanLst;
import com.system.business.repository.IntervalPlanRepository;
import com.system.business.service.IntervalPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 林
 */
@Service
public class IntervalPlanServiceImpl implements IntervalPlanService {
    @Autowired
    private IntervalPlanRepository intervalPlanRepository;
    @Override
    public boolean saveIntervalPlan(IntervalPlan intervalPlan) {
        IntervalPlan obj = intervalPlanRepository.save(intervalPlan);
        if(obj != null){
            return true;
        }
        return false;
    }

    @Override
    public boolean removeIntervalPlanById(int id) {
        if (intervalPlanRepository.existsById(id)) {
            intervalPlanRepository.deleteById(id);
            return true;
        }
        return false;
    }

    @Override
    public boolean modifyIntervalPlan(IntervalPlan intervalPlan) {
        IntervalPlan obj = intervalPlanRepository.save(intervalPlan);
        if(obj != null){
            return true;
        }
        return false;
    }

    @Override
    public IntervalPlan getIntervalPlanById(int id) {
        if (intervalPlanRepository.existsById(id)) {
            return intervalPlanRepository.getReferenceById(id);
        }
        return null;
    }

    @Override
    public List<IntervalPlan> listAllIntervalPlans() {
        return intervalPlanRepository.findAll();
    }

}
